package com.cindata

import com.cindata.dictionary.ComponentType

class Component
{
    String name
    Boolean active = true
    String code

    ComponentType type

    String script
    String message

    Date createdDate = new Date()
    Date modifiedDate = new Date()

    User createBy
    User modifyBy

    static constraints = {
        name maxSize: 64, unqiue: true
        code maxSize: 64, unqiue: true
        script type: "text"
        message maxSize: 256, blank: true, nullable: true
        createBy blank: true, nullable: true
        modifyBy blank: true, nullable: true
    }

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        def user = User.findByUsername(username)
        createBy = user
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}
